//
//  DynamicTypeColorVC.swift
//  ACFrameworkSwift_Example
//
//  Created by c5342925 on 2022/3/16.
//  Copyright © 2022 CocoaPods. All rights reserved.
//

import Foundation
import UIKit
import ACFrameworkSwift

/**
 测试系统 dark/light 模式下颜色动态改变
 */
class DynamicTypeColorVC: UIViewController {
    
    var titleLabel: UILabel = {
        let lab = UILabel()
        lab.text = "Tweaking The System Fonts"
        lab.textAlignment = .center
        lab.numberOfLines = 0
        lab.font = UIFont.systemFont(ofSize: 30)
        lab.theme.textColor = UIColor.preferredDynamicColor(colorStyle: .green7)
        lab.theme.backgroundColor = UIColor.preferredDynamicColor(colorStyle: .grey3)
        return lab
    }()
    
    var contentLabel: UILabel = {
        let lab = UILabel()
        lab.numberOfLines = 0
        lab.textAlignment = .center
        lab.text = "Before you switch to a custom font don’t overlook how much you can tweak the appearance of the system fonts. A quick review of some font APIs that work for both UIKit and SwiftUI."
        lab.font = .systemFont(ofSize: 26)
        lab.textColor = UIColor.black
        return lab
    }()
    
    var footLabel: UILabel = {
        let lab = UILabel()
        lab.text = "Before you switch to a custom font don’t overlook how much you can tweak the appearance of the system fonts. A quick review of some font APIs that work for both UIKit and SwiftUI."
        lab.textAlignment = .center
        lab.numberOfLines = 0
        lab.font = .systemFont(ofSize: 22)
        lab.textColor = UIColor.darkGray
        return lab
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        if #available(iOS 11.0, *) {
            navigationItem.largeTitleDisplayMode = .never
        }
        
        view.backgroundColor = .white
        
        view.addSubview(titleLabel)
        view.addSubview(contentLabel)
        view.addSubview(footLabel)
    }
    
    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        
        let labX: CGFloat = 20
        let labWidth: CGFloat = UIScreen.main.bounds.size.width - 2 * labX
        let maxHeight = CGFloat.greatestFiniteMagnitude
        var labY: CGFloat = 100
        
        let titleSize = titleLabel.systemLayoutSizeFitting(CGSize(width: labWidth, height: maxHeight))
        
        titleLabel.frame = CGRect(x: labX, y: labY, width: labWidth, height: titleSize.height)
        
        labY += titleSize.height + 40
        
        let contentSize = contentLabel.systemLayoutSizeFitting(CGSize(width: labWidth, height: maxHeight))
        
        contentLabel.frame = CGRect(x: labX, y: labY, width: labWidth, height: contentSize.height)
        
        labY += contentSize.height + 40
        
        let footSize = footLabel.systemLayoutSizeFitting(CGSize(width: labWidth, height: maxHeight))
        footLabel.frame = CGRect(x: labX, y: labY, width: labWidth, height: footSize.height)
        
//        print("\n titleLabel.frame = \(titleLabel.frame) \n contentLabel.frame = \(contentLabel.frame) \n")
    }
}
